﻿#include "flyweightfactory.h"

#include <QtGlobal>

#include "concreteflyweight.h"

FlyweightFactory* FlyweightFactory::m_pSelf = Q_NULLPTR;

FlyweightFactory *FlyweightFactory::getInstance()
{
    if(m_pSelf == Q_NULLPTR) {
        m_pSelf = new FlyweightFactory();
    }

    return m_pSelf;
}

Flyweight *FlyweightFactory::getFlyweight(QString key)
{
    if (!m_flyweightMap.contains(key)) {
        Flyweight* flyweight = new ConcreteFlyweight(key);
        m_flyweightMap.insert(key, flyweight);
    }

    return m_flyweightMap.value(key);
}

FlyweightFactory::FlyweightFactory()
{

}
